/**
 * 
 */
	function loaddata(){
		
		var role = "";
		var aurl = pms_url + "sys/user/getUserRole";
		var param = {};
		$.ajax({  
	        type : "post",  
	        url : aurl,  
	        data : param,
	        dataType : "json", 
	        async : false,  //同步
	        success : function(data){  
	           data = eval(data);  
		   		if (data.err_msg=="success") {
		   			role = data.result;
		   			if(role!="admin"){
		   				$('#btnAdd').hide();
		   			}
				}
				else {
					alert("error");
				}
	        }  
	    });
		
		var allFlag = $("#allFlag").val();
		var pno = $("#pagenum").val();
		var from_date=$("#from_date").val();
		var to_date=$("#to_date").val();
		var type=$("#stype").val();
		var ope_id=$("#sope_id").val();
		var factory = $("#sfactory").val();
		var emp_id = $("#sempId").val();
		var emp_name= $("#sname").val();
		var url = pms_url + "cell/performance/listmaintainByDay";
		var params = {factory:factory,emp_id:emp_id,emp_name:emp_name,from_date:from_date,to_date:to_date,type:type,ope_id:ope_id,pno:pno,allFlag:allFlag};
		var obj = load(url,params);//发送请求去服务端请求数据	
		var ary = obj.performanceDay;
		$("#performanceMaintainDaylist").find("tbody").html("");
		$.each(ary, function(index, p) {
//			alert(p.category);
			if(p.category=="操作品质" && p.factory=="CEL"){
				var tr ="<tr role='row'>"+
				"<td>"+p.factory+"</td>"+
				"<td>"+p.fab_date.substr(0,10)+"</td>"+
				"<td>"+p.type+"</td>"+
				"<td>"+p.ope_name+"</td>"+
				"<td>"+p.emp_id+"</td>"+
				"<td>"+p.emp_name+"</td>"+
				"<td>"+p.reason+"</td>"+
				"<td>"+p.group_leader+"</td>"+
				"<td>"+p.class_type+"</td>"+
				"<td>"+ ((role=="admin")?   "<button type='button' class='btn red btn-outline btn-xs del' value="+p.id+">删除</button>":"" ) +  "</td>"+
				"</tr>";
				$("#performanceMaintainDaylist").find("tbody").append(tr);
			}
	 });
	}

	$(function () {
		loaddata();
//		TableDatatablesEditable.init();
		
		
		//重置
		$("#btnReset").on('click', function () {
			$("#searchform input").val("");
			$("#searchform select").val("");
		});	
		
		
		//绑定add单击事件
		$('#btnAdd').on('click', function () {
//			$('#modalAdd').find("span[id='lblAddTitle']").html("新增用户"); 
			$('#modalAdd').find("input").val("");
			$('#modalAdd').find("textarea").val("");
			$('#modalAdd').modal("show");
		});
		//查询
		$('#btnSearch').on('click', function () {
			$("#pagenum").val(1);
			loaddata();
			
		});
		$("#btnAddData").on('click', function () {
			var bootstrapValidator = $("#basicform").data('bootstrapValidator');
			   bootstrapValidator.validate();
			   if(bootstrapValidator.isValid()){
					var factory=$("#factory").val();
					var fabDate = $("#fabDate").val();
					var type = $("#type").val();
					var ope_id = $("#ope_id").val();
					var emp_id = $("#emp_id").val();
					var emp_name = $("#emp_name").val();
					var group_leader = $("#group_leader").val();
					var class_type = $("#class_type").val();
					var reason = $("#reason").val();
					var category="操作品质";
					
					var param = {factory:factory,fabDate:fabDate,type:type,ope_id:ope_id,emp_id:emp_id,
							emp_name:emp_name,group_leader:group_leader,class_type:class_type,category:category,reason:reason};
					var url = pms_url + "cell/performance/createByDay"; 
					$.ajax({  
				        type : "post",  
				        url : url,  
				        dataType: "json", 
				        data : param, 
				        async : false,  //同步
				        success : function(data){ 
					    		if(data.err_msg=="success"){
					    			alert("保存成功");
									$('#modalAdd').modal("hide");
//									loaddata();
									window.location.reload();
					    		}else {
					    			alert(data.err_msg);
					    		}
				        	}
				        });				   
			   }
			   else return;
		});
		
		//删除员工的岗位信息
		$(document).on('click', ".del",function () {
			var id = $(this).val();
//			alert(typeof(id));
			var param = {id:id};
			var delurl = pms_url + "cell/performance/deleteByDay";
			$.post(delurl, param, function(data) {
				if(data.err_msg=="success"){
					alert("删除成功！");
					loaddata();
//					$("#deptlist").find("tbody").html("");
//					getdept(data.emp_id);	
				}
			},"json");
		});
		
		
		//日期空间绑定事件
		$("div").delegate(".form_date","focusin",function(){
			$('.form_date').datetimepicker({
				  language: 'zh-CN',/*加载日历语言包，可自定义*/
				  pickerPosition: 'bottom-left',
				  weekStart: 1,
				  todayBtn: 1,
				  autoclose: 1,
				  todayHighlight: 1,
				  startView: 2,
				  minView: 2,
				  forceParse: 0,
				  format:"yyyy-mm-dd"
			    }).on('hide',function(e) {
			    	 $('#basicform').data('bootstrapValidator')  
			    	 .updateStatus('fabDate', 'NOT_VALIDATED',null)  
			    	 .validateField('fabDate'); 
			    });
		});
		
	
		$('#basicform').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok validator',
                invalid: 'glyphicon glyphicon-remove validator',
                validating: 'glyphicon glyphicon-refresh validator'
            },
            fields: {/*验证*/
            	factory: {/*键名username和input name值对应*/
                    message: 'The factory is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '工厂不能为空'
                        }
                    }
            	},
            	type: {/*键名username和input name值对应*/
                    message: 'The type is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '异常类别不能为空'
                        }
                    }
                },
                emp_id: {
                    message: 'The emp_id is not valid',
                    validators: {
                        notEmpty: {
                            message: '工号不能为空'
                        }
                    }
                },
                group_leader: {
                    message: 'The group_leader is not valid',
                    validators: {
                        notEmpty: {
                            message: '组长姓名不能为空'
                        }
                    }
                },
                reason: {
                    message: 'The reason is not valid',
                    validators: {
                        notEmpty: {
                            message: '内容不能为空'
                        }
                    }
                },
                fabDate: {
                    message: 'The fabDate is not valid',
                    validators: {
                        notEmpty: {
                            message: '发生日期不能为空'
                        }
                    }

                },
                ope_id: {/*键名username和input name值对应*/
                    message: 'The ope_id is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '异常站点不能为空'
                        }
                    }
                },
                emp_name: {/*键名username和input name值对应*/
                    message: 'The emp_name is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: 'DL姓名不能为空'
                        }
                    }
                },
                class_type: {/*键名username和input name值对应*/
                    message: 'The class_type is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '班别不能为空'
                        },
                        regexp: {/* 只需加此键值对，包含正则表达式，和提示 */
                            regexp: /^[A-C]+$/ ,
                            message: '只能是字母'
                        }
                    }
                }
                
            }
		});
		
	});
//	var TableDatatablesEditable=
//	function(){
//	var e=function(){
//		var a=$("#performanceMaintainDaylist"),
//		l=a.dataTable({lengthMenu:[[10,15,20,-1],[10,15,20,"All"]],pageLength:10,language:{lengthMenu:" _MENU_ records"},columnDefs:[{orderable:!0,targets:[0]},{searchable:!0,targets:[0]}],order:[[0,"asc"]]});
//		};
//							
//		return{init:function(){e()}}}();
			